var app= getApp
Page({
  data:{
    order:null,
    first:true //是否是第一次支付
  },
  onLoad(params){
    const paramsObj = JSON.parse(params.paramsStr)
    this.initData(paramsObj)
  },
  initData(params){
    console.log(".........."+params)
    this.setData({
      order:params
    })
  },
  //模拟支付
  payment(){
    //避免重复支付
    if(this.data.first && wx.getStorageSync('token')!=null){
      let movieOrder = wx.getStorageSync('movieOrder') || []
      movieOrder.unshift(this.data.order)
      
      wx.setStorageSync('movieOrder', movieOrder)
      var movie=JSON.stringify(movieOrder[0])
      console.log(movie)
      //调用存储
      wx.request({
        url: 'http://localhost:8080/movie',
        method:'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          'token':wx.getStorageSync('token')
         },
        data: {
          movie
        },
        success(res){

        }
      })

      wx.showToast({
        title: '支付成功',
      })
      this.setData({
        first:false
      })
     wx.switchTab({
       url: '/pages/tabBar/movie/movie',
     })
    } else {
      wx.showToast({
        title: '已支付或未登录',
        icon:'none'
      })
    }

    
  }
})